# coding: utf-8
from sqlalchemy import BigInteger, Column, DateTime, Integer, String
from sqlalchemy.schema import FetchedValue
from flask_sqlalchemy import SQLAlchemy
from common.models.Shop import Shop
from application import db


class Food(db.Model):
    __tablename__ = 'food'
    __table_args__ = {'schema': 'food_db'}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue())
    original_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue())
    main_image = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue())
    updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    is_recommend = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    is_discount = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    discount = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    present_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue())
    shop_id = db.Column(db.ForeignKey('food_db.shop.id'), nullable=False, index=True, server_default=db.FetchedValue())
    food_type_id = db.Column(db.ForeignKey('food_db.food_type.id'), nullable=False, index=True, server_default=db.FetchedValue())
    is_delete = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())

    shop = db.relationship('Shop', primaryjoin='Food.shop_id == Shop.id', backref='foods')
    food_type = db.relationship('FoodType', primaryjoin='Food.food_type_id == FoodType.id', backref='foods')


class FoodType(db.Model):
    __tablename__ = 'food_type'
    __table_args__ = {'schema': 'food_db'}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
